//
//  QNPhoneInfo.m
//  QNReuseTool
//
//  Created by rsh on 2019/10/15.
//  Copyright © 2019年 rsh. All rights reserved.
//

#import "QNPhoneInfo.h"
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>


@implementation QNPhoneInfo

/// 系统版本号
+ (NSString *)systemVersion
{
    return [[UIDevice currentDevice] systemVersion];
}

/// app版本
+ (NSString *)appVersion
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleShortVersionString"];
}


/// app Build 版本号
+ (NSString *)appBuild
{
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleVersion"];
}


/// 分辨率，宽X高
+ (NSString *)resolution
{
    CGSize size = [[UIScreen mainScreen] bounds].size;
    CGFloat scale = [[UIScreen mainScreen] scale];
    CGFloat width = scale * size.width;
    CGFloat height = scale * size.height;
    return [NSString stringWithFormat:@"%dX%d", (int)width, (int)height];
}


/// 移动网络号码
+ (NSString *)mnc
{
    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = info.subscriberCellularProvider;
    if (carrier == nil) {
        return nil;
    }
    
    //获取MCC(移动国家码)
    NSString *mcc = [carrier mobileCountryCode];
    //获取MNC(移动网络码)
    NSString *mnc = [carrier mobileNetworkCode];
    if (mcc.length <= 2) {// || mnc.length <= 2
        return nil;
    }
    
    //判断运营商
    if ([[mcc substringWithRange:NSMakeRange(0, 3)] isEqualToString:@"460"]) {
        return mnc;
    }
    
    return nil;
}


/// bundleIdentifier 最后的标记
+ (NSString *)brandID
{
    NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
    NSArray *array = [identifier componentsSeparatedByString:@"."];
    return array.lastObject;
}

/// 手机语言编号（0：简体 1：繁体 2：英文）
+ (int)languageCode
{
    NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
    
    if ([language isEqualToString:@"zh-Hans"] || [language isEqualToString:@"zh-Hans-CN"]) {
        return 0;
    }
    if ([language isEqualToString:@"zh-Hant"] || [language isEqualToString:@"zh-Hant-CN"]) {
        return 1;
    }
    
    return 2;
}


@end
